﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using Realms;
using TestRealm.Models;

namespace TestRealm;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        Students = realm.All<StudentEntity>();
        var dogs = realm.All<DogEntity>().ToArray();
        var cats = realm.All<CatEntity>().ToArray();
        InitializeComponent();
    }

    Realm realm = App.Realm!;

    public IEnumerable<StudentEntity> Students { get; set; }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        realm.Write(() =>
        {
            //realm.Add(new StudentEntity { Name = $"student {Path.GetRandomFileName()}" });
            realm.Add(new DogEntity { Name = $"dog {Path.GetRandomFileName()}", DogAge = 11 });
            realm.Add(new CatEntity { Name = $"cat {Path.GetRandomFileName()}", CatAge = 22 });
        });
    }
}
